/**
 * 
 */
package com.gr.staffpm.pages.admin.role;

import org.apache.shiro.SecurityUtils;
import org.apache.wicket.PageParameters;
import org.apache.wicket.markup.html.basic.Label;
import org.apache.wicket.markup.html.panel.FeedbackPanel;
import org.apache.wicket.spring.injection.annot.SpringBean;
import org.wicketstuff.annotation.mount.MountPath;
import org.wicketstuff.annotation.strategy.MountHybrid;

import com.gr.staffpm.StaffPMWebPage;
import com.gr.staffpm.datatypes.Role;
import com.gr.staffpm.pages.error.UnauthorizedPage;
import com.gr.staffpm.security.constants.StaffPMRoles;
import com.gr.staffpm.security.service.UserService;


/**
 * @author Graham Rhodes 2 May 2011 21:09:58
 */
@MountHybrid
@MountPath(path = "secure/admin/EditRole")
public class EditRole extends StaffPMWebPage {

    @SpringBean(name = "userService")
    private UserService userService;
    private final Role role;

    public EditRole(PageParameters parameters) {
        super();
        this.role = userService.getRole(parameters.getAsInteger("id"));
        super.onBeforeRender();

        //TODO check permissions for edit permission
        if (SecurityUtils.getSubject().hasRole(StaffPMRoles.ADMIN)) {
            //Header
            add(new Label("roleEditName", "Edit Role: " + role.getRole()));

            add(new FeedbackPanel("feedback"));

            //Form
            add(new EditRoleForm("editRoleForm", userService, role));
        } else
            setResponsePage(UnauthorizedPage.class);
    }

    /* (non-Javadoc)
     * @see com.gr.staffpm.StaffPMWebPage#getTitle()
     */
    @Override
    public String getTitle() {
        return "StaffPM - Edit Role";
    }

}
